package com.rabbitmq.demo.listener;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.rabbitmq.demo.datasource.OrderSource;
import com.rabbitmq.demo.entity.Order;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyMeetingListener {

    @RabbitListener(queues = "q.go.dlx")
    public void onMessage(Message message, Channel channel) throws IOException {

        String order = new String(message.getBody(), message.getMessageProperties().getContentEncoding());
        Order orderPO = JSONObject.parseObject(order, Order.class);
        System.out.println("id为"+orderPO.getOrderNo()+"的订单已支付超时！");
        OrderSource.save(orderPO);
        // 消息确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }


}
